package com.touzbi.hss.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import com.touzbi.hibernate.util.HibernateUtil;
import com.touzbi.hss.beans.Patient;
import com.touzbi.hss.bo.PatientBO;

@WebServlet("/patient")
public class PatientServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String PATIENT_JSP = "/WEB-INF/patient.jsp";
	private static final String PATIENT_ATT = "patient";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();

		PatientBO patientBO = new PatientBO(session);
		Patient patient = patientBO.getPatient(req);

		session.getTransaction().commit();

		req.setAttribute(PATIENT_ATT, patient);
		this.getServletContext().getRequestDispatcher(PATIENT_JSP)
				.forward(req, resp);
	}

}
